package com.zhipu.balance.ui.home.system.device

import android.os.Bundle
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import com.blankj.utilcode.util.SPUtils
import com.zhipu.balance.R
import com.zhipu.balance.databinding.ActivityDeviceBinding
import com.zhipu.balance.ui.BaseActivity
import com.zhipu.balance.ui.vm.home.system.device.DeviceViewModel
import com.zhipu.balance.utils.InitializeUtils

/**
 * 设备信息
 */
class DeviceActivity : BaseActivity<ActivityDeviceBinding>(){


    //VM
    var mDeviceViewModel: DeviceViewModel? = null

    override fun initCreate() {
        super.initCreate()
        InitializeUtils.AppComponent()?.doInjectionMain(this)
        mDeviceViewModel = ViewModelProvider(this, viewModelFactory)[DeviceViewModel::class.java]
    }


    /**
     * 初始化根布局
     *
     * @return 布局layout的id
     */
    override fun initContentView(savedInstanceState: Bundle?): Int {
        return R.layout.activity_device
    }


    override fun initView() {
        super.initView()
        binding.viewModel = mDeviceViewModel
        //编号生成
        mDeviceViewModel?.NumberGeneration?.observe(this, Observer {
            binding.NiceSpinner.attachDataSource(it)
        })
        //自动打印
        mDeviceViewModel?.mAutomaticPrinting?.observe(this,Observer<Boolean> {
            SPUtils.getInstance().put("AutomaticPrinting", it)
        })
        //线性定标
        mDeviceViewModel?.mLinearScaling?.observe(this, Observer {
            SPUtils.getInstance().put("LinearScaling", it)
        })
        //不完善细分
        mDeviceViewModel?.mImperfectSubdivision?.observe(this, Observer {
            SPUtils.getInstance().put("ImperfectSubdivision", it)
        })
    }


    override fun initData() {
        super.initData()


    }


    override fun initViewObservable() {
        super.initViewObservable()
        //编号生成
        binding.NiceSpinner.setOnSpinnerItemSelectedListener { parent, view, position, id ->
            SPUtils.getInstance().put("SerialNumber", parent.getItemAtPosition(position).toString())
        }

    }


}